package com.addzero.web.modules.sys.user.test

import com.addzero.web.infra.jackson.parseObject
import com.addzero.web.infra.jackson.toJson
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonValue
import org.babyfish.jimmer.sql.EnumItem

/**
 * /**
 * 性别  0：男
1=女
2-未知
*/
 *
 * @author AutoDDL
 * @date 2025-04-06 23:04:59
 */
enum class EnumGender(
    val code: String?,
    val desc: String
) {
    /**
     * 男
     */
    @EnumItem(name = "0")
    NAN("0", "男"),

    /**
     * 女
     */
    @EnumItem(name = "1")
    NU("1", "女"),

    /**
     * 未知
     */
    @EnumItem(name = "2")
    WEIZHI("2", "未知");

    @JsonValue
    fun serialize(): Option = Option(code, desc)

    companion object {
        data class Option(val code: String?, val desc: String)

        @JsonCreator
        fun deserialize(code: String): EnumGender? = entries.firstOrNull { it.code == code }

        @JsonCreator
        fun deserializeFromOption(opt: Option): EnumGender? = entries.firstOrNull { it.code == opt.code }

        @JsonCreator
        fun deserializeFromDesc(desc: String): EnumGender? = entries.firstOrNull { it.desc == desc }


    }


}
